import {createStore} from "vuex";

const store = createStore({
    state(){
        return{
            account:null,
            cartList:[
                //id用于绑定删除按钮，点击删除按钮通过id删除对应商品
                // { id : 1, Item_Picture : 'this is picture', Item_Id : 'EST-4', Description : 'Spotted Koi', Price : 18.50, Count : 1},
                // { id : 2, Item_Picture : 'this is picture', Item_Id : 'EST-13', Description : 'Green Adult Iguana', Price : 18.50, Count : 1},
                // { id : 3, Item_Picture : 'this is picture', Item_Id : 'EST-8', Description : 'Green Adult Iguana', Price : 18.50, Count : 1}
            ],
            totalPrice:null
        }
    },
    mutations:{
        setAccount(state, account){
            state.account = account
        },
        clearAccount(state){
            state.account = null;
        },
        setcartList(state, cartList){
            state.cartList = cartList
        },
        setTotalPrice(state, totalPrice){
            state.totalPrice = totalPrice
        }
    },
    //后面添加actions和getters
    actions : {
        login({ commit }, account){
            commit('setAccount', account)
        },
        logout({ commit }){
            commit('clearAccount')
        },
        update({commit}, account){
            commit('setAccount',account)
        },
        setTotalPrice({ commit }, totalPrice){
            commit('setTotalPrice', totalPrice)
        }
    },
    getters : {
        getAccount(state) {
            return state.account
        },
        getcartList(state) {
            return state.cartList;
		}
    }
})

export default store;